const app = getApp()

const utils=require('../../common/utils.js');

Page({
  data:{
    nbFrontColor: '#000000',
    nbBackgroundColor: '#ffffff',
    color: "window",
    loading: false,
    disabled:false,
    date: '2016-09-01',
    region: ['广东省', '广州市', '海珠区'],
    userId: '',
    passWord: '',
    comFirmPassWord: '',
    userName: '',
    mobilePhone: '',
    sex: '',
    age: '',
    birthDay: '',
    address: ''
  },
  bindDateChange: function(e) {
    console.log('时间picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindRegionChange: function (e) {
    console.log('地址picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },

  treg: function treg() {
    wx.navigateTo({
      url: "./../teacher/tregdit"
    });
  },
  ureg: function ureg() {
    wx.navigateTo({
      url: "./../login/login"
    });
  },
  userId: function userId(e) {
    this.setData({ userId: e.detail.value });
  },
  passWord: function passWord(e) {
    this.setData({ passWord: e.detail.value });
  },
  comFirmPassWord: function comFirmPassWord(e) {
    this.setData({ comFirmPassWord: e.detail.value });
  },
  userName: function userName(e) {
    this.setData({ userName: e.detail.value });
  },
  mobilePhone: function mobilePhone(e) {
    this.setData({ mobilePhone: e.detail.value });
  },
  sex: function sex(e) {
    this.setData({ sex: e.detail.value });
  },
  age: function age(e) {
    this.setData({ age: e.detail.value });
  },
  register:function(){
    var that = this;
    that.loading = false;
    that.setLoading();
    that.disabled = true;
    console.log("点击了文字");

    if (that.data.userId == "") {
      wx.showModal({
        content: "用户名不能为空",
        showCancel: false
      })
    } else if (that.data.passWord == "") {
      wx.showModal({
        content: "登录密码不能为空",
        showCancel: false
      })
    }else if (that.data.comFirmPassWord == "") {
      wx.showModal({
        content: "确认密码不能为空",
        showCancel: false
      })
    }else if (that.data.passWord != that.data.comFirmPassWord) {
      wx.showModal({
        content: "两次密码输入不一致，请重新输入",
        showCancel: false
      })
    }else if (that.data.userName == "") {
      wx.showModal({
        content: "昵称不能为空",
        showCancel: false
      })
    }else if (that.data.mobilePhone == "") {
      wx.showModal({
        content: "手机号不能为空",
        showCancel: false
      })
    }else if (that.data.sex == "") {
      wx.showModal({
        content: "性别不能为空",
        showCancel: false
      })
    }else if (that.data.age == "") {
      wx.showModal({
        content: "年龄不能为空",
        showCancel: false
      })
    }else if (that.data.date == "") {
      wx.showModal({
        content: "出生日期不能为空",
        showCancel: false
      })
    }else if (that.data.region == "") {
      wx.showModal({
        content: "地址不能为空",
        showCancel: false
      })
    }else {
      that.data = {
        "userId": that.data.userId,
        "userName": that.data.userName,
        "passWord": that.data.passWord,
        "comFirmPassWord":that.data.comFirmPassWord,
        "mobilePhone": that.data.mobilePhone,
        "sex": that.data.sex,
        "age": that.data.age,
        "birthDay": that.data.date,
        "address": that.data.region[0] + that.data.region[1] + that.data.region[2]
      };

      utils.request('/register/register.do','POST',this.data,'加载中');
    }
    
    that.loading = true;
    that.disabled = false;
    that.setLoading();
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数

    this.setData({
      registerTitle: '注册',
      registerLoading: true,
      registerFrontColor: '#ffffff',
      registerBackgroundColor: '#1296db',
    })

  },
  onReady:function(){
    // 页面渲染完成
    this.setData({
      registerLoading: false,
    })
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  setDisabled: function (e) {
    this.setData({
      disabled: !this.disabled
    })
  },
  setLoading: function (e) {
    this.setData({
      loading: !this.loading
    })
  }
})

